/*
 * @Author: szx
 * @Date: 2022-03-10 14:27:06
 * @LastEditTime: 2022-03-10 14:40:41
 * @Description:
 * @FilePath: \leetcode\100-199\165\165.js
 */
/**
 * @param {string} version1
 * @param {string} version2
 * @return {number}
 */
var compareVersion = function (version1, version2) {
    // 处理，去掉前导零
    const arr1 = version1.split('.');
    for (let i = 0; i < arr1.length; i++) arr1[i] = parseInt(arr1[i]);
    const arr2 = version2.split('.');
    for (let i = 0; i < arr2.length; i++) arr2[i] = parseInt(arr2[i]);

    let i = 0,
        j = 0;
    while (i < arr1.length && j < arr2.length) {
        if (arr1[i] > arr2[j]) return 1;
        else if (arr1[i] < arr2[j]) return -1;
        i++;
        j++;
    }
    while (i < arr1.length) {
        if (arr1[i] != 0) return 1;
        i++;
    }
    while (j < arr2.length) {
        if (arr2[j] != 0) return -1;
        j++;
    }
    return 0;
};
console.log(compareVersion('1.01', '1.001'));
console.log(compareVersion('1.0', '1.0.0'));
console.log(compareVersion('0.1', '1.1'));
console.log(compareVersion('00.01', '0.1'));
